<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            /* background:url(https://img.zcool.cn/community/01714a5c5901b1a801203d223f67e1.jpg@1280w_1l_2o_100sh.jpg) no-repeat; */
            background-size: cover;
            height: 100vh;
        }

        #canvas {
            margin: auto;
            display: block;
            box-shadow: 0 5px 5px rgba(0, 0, 0, .5);
            background: whitesmoke;
        }
    </style>
</head>

<body>

    <canvas id="canvas"></canvas>

    <script>
        var canvas = document.querySelector("#canvas");
        var WIDTH = 500,
            HEIGHT = 700;

        canvas.width = WIDTH;
        canvas.height = HEIGHT;

        var ctx = canvas.getContext('2d');

        var obj = {
            x: 0,
            y: 0,
            width: 50,
            height: 50,
            color: "blue",
            move: function () {
                obj.x += 5;
                if (obj.x >= WIDTH - 50) {
                    obj.x = 0;
                }
            },
            draw: function (ctx) {
                ctx.fillStyle = obj.color;
                ctx.fillRect(obj.x, obj.y, obj.width, obj.height);
            }
        };

        var timer = setInterval(function () {
            ctx.fillStyle = '#fff';
            ctx.fillRect(0, 0, WIDTH, HEIGHT);


            obj.move();
            obj.draw(ctx);
        }, 1000 / 60);
    </script>
</body>

</html>